package hxs.events.flash.display;
import flash.display.InteractiveObject;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import flash.events.TextEvent;
import flash.Lib;
import hxs.extras.FlashEventsStore;

import hxs.extras.FlashSignal;
import hxs.events.flash.display.DisplayObjectEvents;

/**
 * ...
 * @author Tony Polinelli
 */

class InteractiveObjectEvents extends DisplayObjectEvents
{
	public function new(target:InteractiveObject) 
	{
		super(target);
	}
	
	public static function getEvents(target:InteractiveObject):InteractiveObjectEvents
	{
		return cast FlashEventsStore.getEvents(target);
	}
	
	/* CLICK */
	
	public var click(getCick, never):FlashSignal<MouseEvent>;
	private function getCick():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.CLICK);
	}
	
	public var doubleClick(getDoubleClick, never):FlashSignal<MouseEvent>;
	private function getDoubleClick():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.DOUBLE_CLICK);
	}
	
	/*
	 * Added Release Outside, as its pretty useful ;P 
	 */
	public var releaseOutside(getReleaseOutside, never):FlashSignal<MouseEvent>;
	private function getReleaseOutside():FlashSignal<MouseEvent>
	{
		var releaseOutsideSignal = getNativeSignal("MouseEvent.releaseOutside");
		
		var stageMouseUp = function(_){};
		stageMouseUp = function(_){
			releaseOutsideSignal.dispatch(_);
			Lib.current.stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
		}
			
		mouseDown.add(function(_){
			Lib.current.stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
		});
		
		mouseUp.add(function(_){
			Lib.current.stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
		});
		
		return cast releaseOutsideSignal;
	}

	/* FOCUS */
	
	public var focusIn(getFocusIn, never):FlashSignal<FocusEvent>;
	private function getFocusIn():FlashSignal<FocusEvent>
	{
		return cast getNativeSignal(FocusEvent.FOCUS_IN);
	}
	
	public var focusOut(getFocusOut, never):FlashSignal<FocusEvent>;
	private function getFocusOut():FlashSignal<FocusEvent>
	{
		return cast getNativeSignal(FocusEvent.FOCUS_OUT);
	}
	
	public var keyFocusChange(getKeyFocusChange, never):FlashSignal<FocusEvent>;
	private function getKeyFocusChange():FlashSignal<FocusEvent>
	{
		return cast getNativeSignal(FocusEvent.KEY_FOCUS_CHANGE);
	}
	
	/* KEYBOARD */
	
	public var keyDown(getKeyDown, never):FlashSignal<KeyboardEvent>;
	private function getKeyDown():FlashSignal<KeyboardEvent>
	{
		return cast getNativeSignal(KeyboardEvent.KEY_DOWN);
	}
	
	public var keyUp(getKeyUp, never):FlashSignal<KeyboardEvent>;
	private function getKeyUp():FlashSignal<KeyboardEvent>
	{
		return cast getNativeSignal(KeyboardEvent.KEY_UP);
	}
	
	/* MOUSE */
	
	public var mouseDown(getMouseDown, never):FlashSignal<MouseEvent>;
	private function getMouseDown():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.MOUSE_DOWN);
	}
	
	public var mouseFocusChange(getMouseFocusChange, never):FlashSignal<FocusEvent>;
	private function getMouseFocusChange():FlashSignal<FocusEvent>
	{
		return cast getNativeSignal(FocusEvent.MOUSE_FOCUS_CHANGE);
	}

	public var mouseMove(getMouseMove, never):FlashSignal<MouseEvent>;
	private function getMouseMove():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.MOUSE_MOVE);
	}
	
	public var mouseOut(getMouseOut, never):FlashSignal<MouseEvent>;
	private function getMouseOut():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.MOUSE_OUT);
	}
	
	public var mouseOver(getMouseOver, never):FlashSignal<MouseEvent>;
	private function getMouseOver():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.MOUSE_OVER);
	}

	public var mouseUp(getMouseUp, never):FlashSignal<MouseEvent>;
	private function getMouseUp():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.MOUSE_UP);
	}
	
	public var mouseWheel(getMouseWheel, never):FlashSignal<MouseEvent>;
	private function getMouseWheel():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.MOUSE_WHEEL);
	}
	
	public var rollOut(getRollOut, never):FlashSignal<MouseEvent>;
	private function getRollOut():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.ROLL_OUT);
	}
	
	public var rollOver(getRollOver, never):FlashSignal<MouseEvent>;
	private function getRollOver():FlashSignal<MouseEvent>
	{
		return cast getNativeSignal(MouseEvent.ROLL_OVER);
	}
	
	/* TAB */
	
	public var tabChildrenChange(getTabChildrenChange, never):FlashSignal<Event>;
	private function getTabChildrenChange():FlashSignal<Event>
	{
		return cast getNativeSignal(Event.TAB_CHILDREN_CHANGE);
	}
	
	public var tabEnabledChange(getTabEnabledChange, never):FlashSignal<Event>;
	private function getTabEnabledChange():FlashSignal<Event>
	{
		return cast getNativeSignal(Event.TAB_ENABLED_CHANGE);
	}
	
	public var tabIndexChange(getTabIndexChange, never):FlashSignal<Event>;
	private function getTabIndexChange():FlashSignal<Event>
	{
		return cast getNativeSignal(Event.TAB_INDEX_CHANGE);
	}
	
	/* TEXT */

	public var textInput(getTextInput, never):FlashSignal<TextEvent>;
	private function getTextInput():FlashSignal<TextEvent>
	{
		return cast getNativeSignal(TextEvent.TEXT_INPUT);
	}
	
}